<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>GPDOG</title>
    <link th:href="@{/webjars/bootstrap/4.5.3/css/bootstrap.min.css}" rel="stylesheet">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.js}"></script>
    <link rel="shortcut icon" th:href="@{/img/favicon.ico}"/>
    <link rel="bookmark" th:href="@{/img/favicon.ico}"/>
    <style>
        .lblLabel {
            font-size: 0.8rem;
        }
    </style>
</head>
<body class="text-center" style="background-color: dimgray; color: white;">
    <div th:replace="common::topNav(activePage='config')"></div>

    <div class="d-lg-flex mt-2 mb-3">
        <div class="col-lg-3"></div>

        <div class="col-lg-6 text-left">
            <h5 class="text-info">钉钉消息配置</h5>
            <div class="form-group">
                <label class="lblLabel">URL</label>
                <input class="form-control lblLabel" type="text" id="dingUrl" th:value="${dingSet.url}">
                <label class="lblLabel mt-2">Keyword</label>
                <input class="form-control lblLabel" type="text" id="dingKeyword" th:value="${dingSet.keyword}">
            </div>

            <div class="d-inline text-left">
                <div class="form-check form-check-inline mr-2" style="margin-right: 0rem;">
                    <input class="form-check-input" type="checkbox" id="dingMsgCheck" th:checked="${dingSet.dingActive}">
                    <label class="form-check-label lblLabel" for="dingMsgCheck">生效</label>
                </div>
                <button class="btn btn-sm btn-primary" type="button" id="dingBtn">保存</button>
                <label class="text-warning lblLabel" id="respMsg"></label>
            </div>
        </div>

        <hr class="mt-3 mb-3"/>

        <div class="mt-2 col-lg-6 text-left">
            <h5 class="text-info">微信推送消息设置</h5>
            <div class="form-group">
                <label class="lblLabel">UID</label>
                <input class="form-control lblLabel" type="text" id="wxUID" th:value="${dingSet.wxUID}">
            </div>

            <div class="d-inline text-left">
                <div class="form-check form-check-inline mr-2" style="margin-right: 0rem;">
                    <input class="form-check-input" type="checkbox" id="wxMsgCheck" th:checked="${dingSet.wxActive}">
                    <label class="form-check-label lblLabel" for="wxMsgCheck">生效</label>
                </div>
                <button class="btn btn-sm btn-primary" type="button" id="wxBtn">保存</button>
                <label class="text-warning lblLabel" id="respMsgWX"></label>
            </div>
        </div>

        <div class="col-lg-3"></div>
    </div>
</body>
<script>
    $('#dingBtn').click(function (){
        const url = $('#dingUrl').val().trim();
        const keyword = $('#dingKeyword').val().trim();
        if(url.length<10 || keyword.length<1) {
            $('#respMsg').text("参数错误");
            return;
        }

        const dingActive = $('#dingMsgCheck').prop('checked');

        const jsonParam = JSON.stringify({"url":url, "keyword":keyword, "dingActive":dingActive});

        $.ajax({
            url:'svUpDingSet',
            type:'POST',
            async:false,
            data:jsonParam,
            timeout:3000,
            contentType: "application/json;charset=UTF-8",
            success:function(result){
                if(""+result.message == "success") {
                    $('#respMsg').text("成功");
                }else {
                    $('#respMsg').text('保存失败！'+result.message);
                }
            },
            error:function(result){
                $('#respMsg').text('保存失败！'+result.message);
            }
        })
    });

    $('#wxBtn').click(function (){
        const UID = $('#wxUID').val().trim();
        if(UID.length<10) {
            $('#respMsgWX').text("UID不合法");
            return;
        }

        const wxActive = $('#wxMsgCheck').prop('checked');

        const jsonParam = JSON.stringify({"wxUID":UID, "wxActive":wxActive});

        $.ajax({
            url:'svUpWxSet',
            type:'POST',
            async:false,
            data:jsonParam,
            timeout:3000,
            contentType: "application/json;charset=UTF-8",
            success:function(result){
                if(""+result.message == "success") {
                    $('#respMsgWX').text("保存成功");
                }else {
                    $('#respMsgWX').text('保存失败！'+result.message);
                }
            },
            error:function(result){
                $('#respMsgWX').text('保存失败！'+result.message);
            }
        })
    });
</script>
<script th:src="@{/webjars/bootstrap/4.5.3/js/bootstrap.min.js}"></script>
</html>